package com.mojang.ld22.screen;


import com.mojang.ld22.gfx.Color;
import com.mojang.ld22.gfx.Font;
import com.mojang.ld22.gfx.Screen;
import com.mojang.ld22.sound.Sound;

public class WorldSelectionMenu extends Menu {
	private Menu parent;
	private int selected = 0;
	private static final String[] options = { "Normal World", "Hell World", "Space Land", "Main Menu" };
	
	public WorldSelectionMenu(Menu parent) {
		this.parent = parent;
	}

	public void tick() {
		if (input.up.clicked) selected--;
		if (input.down.clicked) selected++;

		int len = options.length;
		if (selected < 0) selected += len;
		if (selected >= len) selected -= len;

		if (input.attack.clicked || input.menu.clicked) {
			if (selected != 3) launchGame(selected);
			else game.setMenu(parent);
		}
	}
	
	public void launchGame(int worldType)
	{
		Sound.test.play();
		game.resetGame(worldType);
		game.setMenu(null);
	}

	public void render(Screen screen) {
		screen.clear(3);

		Font.draw("Select a world type:", screen, (screen.w - 20 * 8) / 2, (6) * 8, Color.get(-1, 333, 333, 333));
		
		for (int i = 0; i < 4; i++) {
			String msg = options[i];
			int col = Color.get(-1, 222, 222, 222);
			if (i == selected) {
				msg = "> " + msg + " <";
				col = Color.get(-1, 555, 555, 555);
			}
			if(i == options.length-1)
				i += 1;
			Font.draw(msg, screen, (screen.w - msg.length() * 8) / 2, (8 + i) * 8, col);
		}
	}
}
